package com.tqz.rc.spring.cloud.ribbon;

import com.netflix.loadbalancer.Server;
import com.tqz.rc.api.Instance;

/**
 * <p>
 *
 * @author tianqingzhao
 * @since 2021/9/9 11:06
 */
public class TqzRcServer extends Server {

    private MetaInfo metaInfo;

    private Instance instance;

    public TqzRcServer(Instance instance) {
        super(instance.getIp(), instance.getPort());
        this.instance = instance;
        metaInfo = new MetaInfo() {
            @Override
            public String getAppName() {
                return instance.getServiceName();
            }

            @Override
            public String getServerGroup() {
                return null;
            }

            @Override
            public String getServiceIdForDiscovery() {
                return null;
            }

            @Override
            public String getInstanceId() {
                return instance.getInstanceId();
            }
        };
    }

    @Override
    public MetaInfo getMetaInfo() {
        return metaInfo;
    }

    public Instance getInstance() {
        return instance;
    }
}
